const path = require('path');
const nodeExternals = require('webpack-node-externals');

module.exports = {
  target: 'node',

  module: {
    rules: [
      {
        test: /\.js?$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
      {
        test: /\.node$/,
        exclude: /node_modules/,
        use: 'node-loader',
      },
    ],
  },

  entry: {
    main: path.join(__dirname, 'electron/main.js'),
    preload: path.join(__dirname, 'electron/preload.js'),
  },

  output: {
    path: path.join(__dirname, 'dist/main'),
  },

  resolve: {
    extensions: ['.js', '.jsx', '.json', '.ts', '.tsx', '.node'],
    alias: {
      '~native': path.resolve(__dirname, 'native'),
      '~resources': path.resolve(__dirname, 'resources'),
      '~build': path.resolve(__dirname, 'build'),
    },
  },

  externals: [nodeExternals()],

  node: {
    __dirname: false,
    __filename: false,
  },
};
